<style lang="less">
@import "@/styles/table-common.less";
.btn-box {
  // padding: 10px 12px 10px 0;
  height: 32px;
  display: flex;
  align-items: center;
  span {
    margin-left: 15px;
  }
}
.detail-modal {
  .form {
    div {
      display: flex;
      margin-bottom: 10px;
      span {
        width: 130px;
      }
      input {
        flex: 1;
        border: 1px solid #e8eaec;
        outline: none;
        text-indent: 16px;
        color: #515a6e;
      }
    }
  }
  .refund-num {
    margin-top: 15px;
  }
}
.statistic {
  display: flex;
  margin-bottom: 20px;
  li {
    margin-right: 20px;
  }
}
</style> 
<template>
  <div class="search">
    <Card>
      <ul class="statistic">
        <li>
          <span>进出门闸总数：</span>
          <span>{{nums.count}}</span>
        </li>
        <li>
          <span>当月进出门闸总数：</span>
          <span>{{nums.monthCount}}</span>
        </li>
      </ul>
      <Form ref="searchForm" :model="searchForm" inline :label-width="100">
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
          <FormItem label="日期">
            <DatePicker
              :options="options"
              v-model="selectDate"
              type="daterange"
              format="yyyy-MM-dd"
              clearable
              @on-change="selectDateRange"
              placeholder="选择起始时间"
              style="width: 200px"
            ></DatePicker>
          </FormItem>
          <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
          </FormItem>
        </Row>
      </Form>

      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
  </div>
</template>
<script>
import { scUserInOutRecordByCondition } from "@/api/index";
import { shortcuts } from "@/libs/shortcuts";
// import addEdit from "./addEdit.vue";
export default {
  name: "user-manage",
  components: {
    // addEdit,
  },
  props: ["uCompanyId"],
  data() {
    return {
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      selectDate: "",
      openSearch: true,
      idenList: [], //角色状态
      options: {
        shortcuts: shortcuts,
      },
      searchForm: {
        pageNumber: 1,
        pageSize: "10",
        sort: "createTime",
        order: "desc",
      },
      columns: [
        {
          title: "昵称",
          key: "nickName",
          minWidth: 140,
          align: "center",
          fixed: "left",
        },
        {
          title: "手机号",
          key: "mobile",
          minWidth: 140,
          align: "center",
        },
        {
          title: "进出时间",
          key: "inOutDate",
          minWidth: 200,
          align: "center",
        },
        {
          title: "进出方式",
          key: "inOut",
          minWidth: 140,
          align: "center",
          render: (h, params) =>{
            let nodeTxt = ''
            if(params.row.inOut == 0) {
                nodeTxt = '出'
            } else if (params.row.inOut == 1) {
                nodeTxt = '进'
            }
            return h('span', nodeTxt)
          }
        },
        
      ],
      data: [],
      nums: {
          count: 0,
          monthCount: 0,
      }
    };
  },
  methods: {
    init() {
      this.getDataList();
      // this.getScOrderByConditionData()
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      this.loading = true;
      scUserInOutRecordByCondition({...this.searchForm, uCompanyId: this.uCompanyId}).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data = res.result.page.content
          this.total = res.result.page.totalElements

          this.nums = {
                count: res.result.count,
                monthCount: res.result.monthCount
          }
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
        }
      });
    },

    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    handleReset() {
      this.selectDate = "";
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
  },
  created() {
  },
  activated() {
    this.init();
  },
  mounted() {
    // 计算高度
    this.height = Number(document.documentElement.clientHeight - 230);
    this.init();
  },
};
</script>